<form name="editEntryForm" data-ng-submit="editEntry()" class="entry-form" ng-if="entry">

<div class="container-fluid">

<!--header-->
<div class="row entry_general_header_td" style="height: 60px">
    <div class="col-md-12">
        <h4>
            <span style="white-space: nowrap">
                <strong class="color-888">EDIT {{entry.type}}</strong>
                <strong>{{entry.partId}}</strong>
            </span>
            <br>
            <small class="font-65em">{{entry.creationTime | date:'medium'}} -
                <a ng-href="profile/{{entry.ownerId}}">{{entry.owner}}</a>
            </small>
        </h4>
    </div>
</div>

<!--fields for the type of entry being edited -->
<div class="row pad-top-5" ng-repeat="field in selectedFields" ng-if="!activePart.isExistingPart">
    <div class="col-md-2 text-right">
        <span style="white-space:nowrap" ng-class="{'font-bold':field.edit}">{{field.label}}
            <span ng-if="field.required" class="required">*</span>
        </span>
    </div>

    <!--short input field-->
    <div class="col-md-10" ng-if="field.inputType==='short'">
        <input type="text" ng-model="activePart[field.schema]" ng-trim="true" ng-focus="field.edit=true"
               ng-blur="field.edit=false" ng-class="{'input_box':!field.invalid, 'input_box_error':field.invalid}"
               maxlength="125" placeHolder="{{field.placeHolder}}" style="width: 205px;">
        <i ng-if="field.help" class="fa fa-question-circle opacity_hover" uib-tooltip="{{field.help}}"
           tooltip-placement="right"></i>
    </div>

    <!-- short input field with email -->
    <div class="col-md-10" ng-if="field.inputType==='withEmail'">
        <input type="text" ng-model="activePart[field.schema]" ng-trim="true" ng-focus="field.edit=true"
               ng-blur="field.edit=false" ng-class="{'input_box':!field.invalid, 'input_box_error':field.invalid}"
               maxlength="125" style="width: 205px;">

        <input type="text" ng-model="activePart[field.schema+'Email']" ng-trim="true" ng-focus="field.edit=true"
               ng-blur="field.edit=false" ng-class="{'input_box':!field.invalid, 'input_box_error':field.invalid}"
               placeholder="Email if known" style="width: 191px;">
    </div>

    <!--options-->
    <div class="col-md-10" ng-if="field.options">
        <select ng-focus="field.edit=true" ng-blur="field.edit=false" class="input_box pull_down"
                ng-model="activePart[field.schema]" size="1"
                ng-options="option.text as option.text for option in field.options"></select>
    </div>

    <!--checkbox-->
    <div class="col-md-10" ng-if="field.inputType==='bool'">
        <input type="checkbox" ng-model="activePart[field.schema]" ng-focus="field.edit=true"
               ng-blur="field.edit=false">
    </div>

    <!--date picker-->
    <div class="col-md-10" ng-if="field.inputType==='date'">
        <div class="input-group">
            <input type="text" ng-model="activePart[field.schema]" show-button-bar="false" show-weeks="false"
                   datepicker-popup="yyyy-MM-dd" class="input_box_group" maxlength="125" is-open="opened"
                   datepicker-options="dateOptions" close-text="Close" style="width: 205px;"
                   ng-focus="field.edit=true" ng-blur="field.edit=false">
            <span class="input-group-addon" style="padding:3px; background-color: #f1f1f1;width: 19px">
                <i class="fa fa-calendar"></i>
            </span>
        </div>
    </div>

    <!--medium input-->
    <div class="col-md-10" ng-if="field.inputType==='medium'">
        <input type="text" ng-model="activePart[field.schema]" maxlength="150" style="width:400px;"
               ng-class="{'input_box':!field.invalid, 'input_box_error':field.invalid}"
               ng-focus="field.edit=true" ng-blur="field.edit=false">
    </div>

    <!--auto complete-->
    <div class="col-md-10" ng-if="field.inputType==='autoComplete'">
        <input type="text" ng-model="activePart[field.schema]" maxlength="150"
               ng-class="{'input_box':!field.invalid, 'input_box_error':field.invalid}"
               placeHolder={{field.placeHolder}} style="width:205px;" typeahead-loading="loadingData"
               uib-typeahead="result for result in getLocation(field.autoCompleteField, $viewValue) | filter:$viewValue"
               ng-focus="field.edit=true" ng-blur="field.edit=false">
        <i ng-show="loadingData" class="fa fa-spinner fa-spin"></i>
    </div>

    <!--add-->
    <div class="col-md-10" ng-if="field.inputType==='add'">
        <span ng-repeat="link in activePart[field.schema]">
            <div ng-if="!$index">
                <input ng-model="activePart[field.schema][$index].value" type="text" maxlength="500"
                       style="width: 400px;"
                       ng-class="{'input_box':!field.invalid, 'input_box_error':field.invalid}"
                       ng-focus="field.edit=true" ng-blur="field.edit=false">
                <span ng-if="activePart[field.schema].length===1" uib-tooltip="Add another" tooltip-placement="right"
                      ng-click="addLink(field.schema, $index)">
                    <i class="fa fa-plus green opacity_hover"></i>
                </span>
            </div>

            <div ng-if="$index" class="input-group pad-top-5">
                <input type="text" ng-model="activePart[field.schema][$index].value" maxlength="125"
                       style="width: 400px;"
                       ng-class="{'input_box_group':!field.invalid, 'input_box_error':field.invalid}"
                       ng-focus="field.edit=true" ng-blur="field.edit=false">
                <span class="input-group-addon" data-ng-click="removeLink(field.schema, $index)" style="padding:3px; background-color:
                 #f1f1f1;width: 19px; border-left: 0">
                    <i class="fa fa-minus delete_icon"></i>
                </span>&nbsp;
                <i class="fa fa-plus green opacity_hover" ng-click="addLink(field.schema, $index)"></i>
            </div>
        </span>
    </div>

    <!-- autocompleteAdd-->
    <div class="col-md-10" ng-if="field.inputType==='autoCompleteAdd'">
        <span ng-repeat="link in activePart[field.schema] track by $index">
            <div ng-if="!$index">
                <input ng-model="link.value" type="text" typeahead-loading="loadingData"
                       ng-class="{'input_box':!field.invalid, 'input_box_error':field.invalid}"
                       ng-change="field.invalid=false"
                       maxlength="125" style="width: 400px;" ng-focus="field.edit=true" ng-blur="field.edit=false"
                       uib-typeahead="result for result in getLocation(field.autoCompleteField, $viewValue)">
                <span ng-if="activePart[field.schema].length===1" uib-tooltip="Add another" tooltip-placement="right"
                      ng-click="addLink(field.schema, $index)"> {{$viewValue}}
                    <i ng-show="loadingData" class="fa fa-spinner fa-spin"></i>
                    <i class="fa fa-plus green opacity_hover"></i>
                </span>
            </div>

            <div ng-if="$index" class="input-group pad-top-5">
                <input type="text" ng-model="activePart[field.schema][$index].value" maxlength="125"
                       style="width: 400px;"
                       ng-class="{'input_box_group':!field.invalid, 'input_box_error':field.invalid}"
                       ng-change="field.invalid=false"
                       ng-focus="field.edit=true" ng-blur="field.edit=false" typeahead-loading="loadingData"
                       uib-typeahead="result for result in getLocation(field.autoCompleteField, $viewValue)">
                <span class="input-group-addon" data-ng-click="removeLink(field.schema, $index)"
                      style="padding:3px; background-color: #f1f1f1;width: 19px; border-left: 0">
                    <i class="fa fa-minus delete_icon"></i>
                </span>&nbsp;
                <i class="fa fa-plus green opacity_hover" ng-click="addLink(field.schema, $index)"></i>
            </div>
        </span>
    </div>

    <!--long-->
    <div class="col-md-10" ng-if="field.inputType==='long'">
        <textarea ng-model="activePart[field.schema]" style="width: 640px; height: 50px;" ng-trim="true"
                  ng-focus="field.edit=true" ng-blur="field.edit=false"
                  ng-class="{'input_box':!field.invalid, 'input_box_error':field.invalid}"></textarea>
    </div>
</div>

<!--if existing part is added then this is displayed instead-->
<div class="row pad-top-5" ng-repeat="field in selectedFields" ng-if="activePart.isExistingPart&&selectedFields">
    <div class="col-md-2 entryLabel text-right">
        <span ng-class="{'entryEditLabel':field.edit}">{{field.label}}</span>
    </div>
    <div class="col-md-10">
        <div>{{activePart[field.schema]}}</div>
    </div>
</div>

<!--sequence and notes -->
<div class="row pad-top-5" ng-if="selectedFields">
    <div class="col-md-12">
        <div class="entry-details-subheader">
            <strong style="color: #233559">SEQUENCE</strong>

            <div class="pull-right">
                <small class="opacity_hover" ng-click="isPaste=false">
                    <i style="font-size:14px" class="fa fa-upload"></i> Upload File
                </small>
                <span style="font-weight: normal; color: #ccc">&nbsp;&nbsp;|&nbsp;&nbsp;</span>
                <small class="opacity_hover" ng-click="isPaste=true">
                    <i style="font-size:14px" class="fa fa-paste"></i> Paste Sequence
                </small>
            </div>
        </div>

        <div class="margin-top-10 font-95em" ng-hide="activePart.hasSequence">
            <div class="alert alert-info" style="margin-bottom: 10px; margin-top: 10px">
                <i style="font-size: 18px" class="fa fa-info-circle pull-left"></i> Supported file formats are
                Genbank, Fasta and SBOL
            </div>

            <div class="alert alert-danger" style="margin-bottom: 10px" ng-if="serverError">
                <i style="font-size: 18px" class="fa fa-exclamation-triangle pull-left"></i> Error parsing file
            </div>

            <!--file upload-->
            <span ng-if="!isPaste && !processingFile">
                <div class="margin-top-20"><input nv-file-select uploader="sequenceFileUpload" type="file"/></div>
                <div style="height: 7px; background-color: #f9f9f9;">
                    <div class="progress-bar" role="progressbar"
                         ng-style="{ 'width': sequenceFileUpload.progress + '%' }"></div>
                </div>
            </span>

            <span ng-if="processingFile">
                <i class="fa fa-spinner fa-gear"></i> Processing file {{processingFile}}
            </span>

            <!--sequence paste-->
            <textarea ng-show="isPaste===true &&!processingFile" ng-model="pastedSequence" class="input_box"
                      placeholder="Paste sequence" rows="14" style="width: 100%; height: 100%;"></textarea>
        </div>

        <div class="margin-top-10" ng-if="activePart.hasSequence" style="height: 600px">
            <ice-vector-viewer entryId="{{activePart.id}}"></ice-vector-viewer>
        </div>
    </div>
</div>

<div class="row pad-top-5" ng-if="selectedFields">
    <div class="col-md-12">
        <div class="entry-details-subheader">
            <strong style="color: #233559">NOTES</strong>
        </div>
    </div>
</div>

<div class="row pad-top-5" ng-if="selectedFields">
    <div class="col-md-2" ng-if="!activePart.isExistingPart"></div>
    <div class="col-md-10" ng-if="!activePart.isExistingPart">
        <textarea class="entry_add_notes_input" ng-model="activePart.longDescription"></textarea>
    </div>
    <div class="col-md-12" ng-if="activePart.isExistingPart">
        {{activePart.longDescription}}
    </div>
</div>

<div class="row pad-top-5" ng-if="selectedFields">
    <div class="col-md-2"></div>

    <div class="col-md-10">
        <button type="submit" class="btn btn-primary font-85em">Submit</button>
        <button type="button" ng-click="cancelEdit()" class="btn btn-default font-85em">Cancel</button>
    </div>
</div>

    <br><br>

</div>

</form>

